<template>
    <a-modal
        :open="addFolderVisible"
        title="新建文件夹"
        @ok="handleAddFolderConfirm"
        @cancel="handleCancel"
    >
        <a-form layout="vertical">
            <a-form-item label="文件夹名称" required>
                <a-input
                    v-model:value="newFolderName"
                    placeholder="请输入文件夹名称"
                    @pressEnter="handleAddFolderConfirm"
                />
            </a-form-item>
        </a-form>
    </a-modal>
</template>
<script setup>
import {message} from 'ant-design-vue';
import {ref,defineProps,defineEmits} from 'vue'
import KnowledgeBaseDetailsApi from "@/common/api/knowledge/knowledgeBaseDetails";
const props = defineProps({
    addFolderVisible:{
        type: Boolean,
        default: false
    },
    knowledgeId:{
        type: String,
        default: ''
    }
});
const emits = defineEmits(['cancel', 'submit','initData']);
const newFolderName = ref('');
// 新增确认方法
const handleAddFolderConfirm = async () => {
    if (!newFolderName.value.trim()) {
        message.error('文件夹名称不能为空');
        return;
    }
    try{
        const params = {
            knowledgeId:props.knowledgeId,
            name: newFolderName.value,
            parentId:0,
            type:"dir"
        }
        const result = await KnowledgeBaseDetailsApi.save(params);
        if(result.success){
            newFolderName.value = '';
            emits('initData')
            handleCancel();
        }
    }catch (e){
        console.log('创建失败:'+e)
    }

};
function handleCancel(){
    emits('cancel')
}
</script>
<style scoped lang="scss">
/* 在 style 中添加 */
.ant-modal-body {
    padding: 24px;

    .ant-form-item {
        margin-bottom: 0;
    }

    .ant-input {
        margin-top: 8px;
    }
}
</style>
